import { Alert } from 'antd';
import { LocoRenderer } from '@ydc/loco-renderer';

export default function BuiltPageRenderer(props: { schema: any; extraEnv?: Record<string, any> }) {
  const { schema, extraEnv } = props;

  try {
    let parsedSchema = schema;

    if (typeof schema === 'string') {
      parsedSchema = JSON.parse(schema);
    }

    // 新版本的 Schema, 用新的渲染器进行渲染
    return (
      <LocoRenderer
        key={'counter'}
        schema={parsedSchema}
        clientType={extraEnv?.isPrint ? ('print' as any) : undefined}
      />
    );
  } catch (error) {
    return <Alert type="error" showIcon message={`渲染失败: 原因查看控制台`} />;
  }
}
